package com.example.shopping_web_back.service;

import com.example.shopping_web_back.mapper.BusinessMapper;
import com.example.shopping_web_back.pojo.Business;
import com.example.shopping_web_back.pojo.Goods;
import com.example.shopping_web_back.service.impl.BusinessServiceImpl;
import com.example.shopping_web_back.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

//主要用于定义顾客（用户）服务层函数的具体内容
@Service
public class BusinessService implements BusinessServiceImpl {

    @Autowired
    private BusinessMapper businessMapper;

    @Override
    public Business findByBusinessName(String business_name) {
        return businessMapper.findByBusinessName(business_name);
    }

    @Override
    public void register(String businessName, String password) {
        businessMapper.add(businessName,password);
    }

    @Override
    public void update(Business business) {
        businessMapper.update(business);
    }

    @Override
    public void updateImage(String imageUrl) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer)map.get("id");
        businessMapper.updateImage(imageUrl, id);
    }

    @Override
    public void updatePassword(String newPwd) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer)map.get("id");
        businessMapper.updatePassword(newPwd, id);
    }

    @Override
    public List<Goods> searchAllGoods(String businessName) {
        return businessMapper.searchAllGoods(businessName);
    }

}
